<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>流与二进制 | 星月前端博客</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/favicon.ico">
    <meta name="description" content="The top of the mountain is not the end, nor is the other mountain.">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/assets/css/0.styles.f057962c.css" as="style"><link rel="preload" href="/assets/js/app.b0d6e6c9.js" as="script"><link rel="preload" href="/assets/js/3.3f705cf6.js" as="script"><link rel="preload" href="/assets/js/1.5432b32a.js" as="script"><link rel="preload" href="/assets/js/51.d9305c51.js" as="script"><link rel="prefetch" href="/assets/js/10.a8f43ca8.js"><link rel="prefetch" href="/assets/js/11.f3a618ea.js"><link rel="prefetch" href="/assets/js/12.b0d83b4c.js"><link rel="prefetch" href="/assets/js/13.f1fb4696.js"><link rel="prefetch" href="/assets/js/14.e5bc98a2.js"><link rel="prefetch" href="/assets/js/15.50519e37.js"><link rel="prefetch" href="/assets/js/16.3c6a720c.js"><link rel="prefetch" href="/assets/js/17.39fb3a22.js"><link rel="prefetch" href="/assets/js/18.76eb3752.js"><link rel="prefetch" href="/assets/js/19.7e9cf824.js"><link rel="prefetch" href="/assets/js/20.91bdeca4.js"><link rel="prefetch" href="/assets/js/21.136cc362.js"><link rel="prefetch" href="/assets/js/22.ec4f40f8.js"><link rel="prefetch" href="/assets/js/23.50127d3e.js"><link rel="prefetch" href="/assets/js/24.793b4c66.js"><link rel="prefetch" href="/assets/js/25.e2402b1b.js"><link rel="prefetch" href="/assets/js/26.cda4008e.js"><link rel="prefetch" href="/assets/js/27.8f1f302e.js"><link rel="prefetch" href="/assets/js/28.15cd65f2.js"><link rel="prefetch" href="/assets/js/29.00adce9e.js"><link rel="prefetch" href="/assets/js/30.c29d2b5d.js"><link rel="prefetch" href="/assets/js/31.40db97f7.js"><link rel="prefetch" href="/assets/js/32.70ed39cf.js"><link rel="prefetch" href="/assets/js/33.b0f7cfc3.js"><link rel="prefetch" href="/assets/js/34.f0a63370.js"><link rel="prefetch" href="/assets/js/35.88e20dad.js"><link rel="prefetch" href="/assets/js/36.13f74559.js"><link rel="prefetch" href="/assets/js/37.1d442fc4.js"><link rel="prefetch" href="/assets/js/38.84077197.js"><link rel="prefetch" href="/assets/js/39.51512938.js"><link rel="prefetch" href="/assets/js/4.3ce47df9.js"><link rel="prefetch" href="/assets/js/40.1f3d0e52.js"><link rel="prefetch" href="/assets/js/41.8e4ee580.js"><link rel="prefetch" href="/assets/js/42.690cbafe.js"><link rel="prefetch" href="/assets/js/43.c4aa2221.js"><link rel="prefetch" href="/assets/js/44.fb378084.js"><link rel="prefetch" href="/assets/js/45.77700693.js"><link rel="prefetch" href="/assets/js/46.d507cb48.js"><link rel="prefetch" href="/assets/js/47.e3a1008a.js"><link rel="prefetch" href="/assets/js/48.d6c9c78e.js"><link rel="prefetch" href="/assets/js/49.4667e7c0.js"><link rel="prefetch" href="/assets/js/5.6d641d4f.js"><link rel="prefetch" href="/assets/js/50.8ec4f4f5.js"><link rel="prefetch" href="/assets/js/52.db11222b.js"><link rel="prefetch" href="/assets/js/53.61d62d9d.js"><link rel="prefetch" href="/assets/js/54.f20b6c65.js"><link rel="prefetch" href="/assets/js/55.0a4f147e.js"><link rel="prefetch" href="/assets/js/56.cd32d35a.js"><link rel="prefetch" href="/assets/js/57.a5fde1bb.js"><link rel="prefetch" href="/assets/js/58.a0a97490.js"><link rel="prefetch" href="/assets/js/59.1bb4fab1.js"><link rel="prefetch" href="/assets/js/6.5f336290.js"><link rel="prefetch" href="/assets/js/60.e6987c2a.js"><link rel="prefetch" href="/assets/js/61.419fcdc8.js"><link rel="prefetch" href="/assets/js/62.5a9d4e12.js"><link rel="prefetch" href="/assets/js/63.be6ca5ce.js"><link rel="prefetch" href="/assets/js/64.8aef8f94.js"><link rel="prefetch" href="/assets/js/65.16450833.js"><link rel="prefetch" href="/assets/js/66.2969e029.js"><link rel="prefetch" href="/assets/js/67.e3a3c472.js"><link rel="prefetch" href="/assets/js/68.6ff65261.js"><link rel="prefetch" href="/assets/js/69.cf4da88b.js"><link rel="prefetch" href="/assets/js/7.6a1d4e29.js"><link rel="prefetch" href="/assets/js/70.1472620a.js"><link rel="prefetch" href="/assets/js/71.1e7cb0a1.js"><link rel="prefetch" href="/assets/js/72.2bf85313.js"><link rel="prefetch" href="/assets/js/73.d9cb4d96.js"><link rel="prefetch" href="/assets/js/74.0c536977.js"><link rel="prefetch" href="/assets/js/75.4f82c6a8.js"><link rel="prefetch" href="/assets/js/76.42f3f0b7.js"><link rel="prefetch" href="/assets/js/77.70961c41.js"><link rel="prefetch" href="/assets/js/78.2f45f2fc.js"><link rel="prefetch" href="/assets/js/79.a68a9b1c.js"><link rel="prefetch" href="/assets/js/8.378e22b1.js"><link rel="prefetch" href="/assets/js/80.6cb339b8.js"><link rel="prefetch" href="/assets/js/81.5849f124.js"><link rel="prefetch" href="/assets/js/82.f5531d2d.js"><link rel="prefetch" href="/assets/js/83.47badffa.js"><link rel="prefetch" href="/assets/js/84.dece7e94.js"><link rel="prefetch" href="/assets/js/85.d9e7f122.js"><link rel="prefetch" href="/assets/js/86.233d7088.js"><link rel="prefetch" href="/assets/js/87.ce5dff2e.js"><link rel="prefetch" href="/assets/js/88.f976bef7.js"><link rel="prefetch" href="/assets/js/89.8473e540.js"><link rel="prefetch" href="/assets/js/9.9eb4a88c.js"><link rel="prefetch" href="/assets/js/90.d6288b36.js"><link rel="prefetch" href="/assets/js/91.989f4dea.js"><link rel="prefetch" href="/assets/js/92.6ff507f9.js">
    <link rel="stylesheet" href="/assets/css/0.styles.f057962c.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-5bb33761><div data-v-5bb33761><div class="password-shadow password-wrapper-out" style="display:none;" data-v-59e6cb88 data-v-5bb33761 data-v-5bb33761><h3 class="title" data-v-59e6cb88>星月前端博客</h3> <p class="description" data-v-59e6cb88>The top of the mountain is not the end, nor is the other mountain.</p> <label id="box" class="inputBox" data-v-59e6cb88><input type="password" value="" data-v-59e6cb88> <span data-v-59e6cb88>Konck! Knock!</span> <button data-v-59e6cb88>OK</button></label> <div class="footer" data-v-59e6cb88><span data-v-59e6cb88><i class="iconfont reco-theme" data-v-59e6cb88></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59e6cb88>vuePress-theme-reco</a></span> <span data-v-59e6cb88><i class="iconfont reco-copyright" data-v-59e6cb88></i> <a data-v-59e6cb88><span data-v-59e6cb88>星月</span>
          
        <!---->
        2022
      </a></span></div></div> <div class="hide" data-v-5bb33761><header class="navbar" data-v-5bb33761><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.png" alt="星月前端博客" class="logo"> <span class="site-name">星月前端博客</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      博客
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/ES6模块化与异步编程/" class="nav-link"><i class="undefined"></i>
  ES6模块化与异步编程
</a></li><li class="dropdown-item"><!----> <a href="/categories/css/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/categories/TypeScript/" class="nav-link"><i class="undefined"></i>
  TypeScript
</a></li><li class="dropdown-item"><!----> <a href="/categories/html/" class="nav-link"><i class="undefined"></i>
  html
</a></li><li class="dropdown-item"><!----> <a href="/categories/JavaScript/" class="nav-link"><i class="undefined"></i>
  JavaScript
</a></li><li class="dropdown-item"><!----> <a href="/categories/Node.js/" class="nav-link"><i class="undefined"></i>
  Node.js
</a></li><li class="dropdown-item"><!----> <a href="/categories/Vue2/" class="nav-link"><i class="undefined"></i>
  Vue2
</a></li><li class="dropdown-item"><!----> <a href="/categories/Vue3/" class="nav-link"><i class="undefined"></i>
  Vue3
</a></li><li class="dropdown-item"><!----> <a href="/categories/webpack/" class="nav-link"><i class="undefined"></i>
  webpack
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><a href="/docs/theme-reco/" class="nav-link"><i class="iconfont reco-message"></i>
  随记
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系方式
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/858399075" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/xingyueqianduan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="http://blog.yhxweb.top/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i></i>
  QQ:76120220
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="http://blog.yhxweb.top/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i></i>
  WX:15237156071
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-5bb33761></div> <aside class="sidebar" data-v-5bb33761><div class="personal-info-wrapper" data-v-1fad0c41 data-v-5bb33761><img src="/avatar.png" alt="author-avatar" class="personal-img" data-v-1fad0c41> <h3 class="name" data-v-1fad0c41>
    星月
  </h3> <div class="num" data-v-1fad0c41><div data-v-1fad0c41><h3 data-v-1fad0c41>82</h3> <h6 data-v-1fad0c41>Articles</h6></div> <div data-v-1fad0c41><h3 data-v-1fad0c41>9</h3> <h6 data-v-1fad0c41>Tags</h6></div></div> <ul class="social-links" data-v-1fad0c41></ul> <hr data-v-1fad0c41></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      博客
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/ES6模块化与异步编程/" class="nav-link"><i class="undefined"></i>
  ES6模块化与异步编程
</a></li><li class="dropdown-item"><!----> <a href="/categories/css/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/categories/TypeScript/" class="nav-link"><i class="undefined"></i>
  TypeScript
</a></li><li class="dropdown-item"><!----> <a href="/categories/html/" class="nav-link"><i class="undefined"></i>
  html
</a></li><li class="dropdown-item"><!----> <a href="/categories/JavaScript/" class="nav-link"><i class="undefined"></i>
  JavaScript
</a></li><li class="dropdown-item"><!----> <a href="/categories/Node.js/" class="nav-link"><i class="undefined"></i>
  Node.js
</a></li><li class="dropdown-item"><!----> <a href="/categories/Vue2/" class="nav-link"><i class="undefined"></i>
  Vue2
</a></li><li class="dropdown-item"><!----> <a href="/categories/Vue3/" class="nav-link"><i class="undefined"></i>
  Vue3
</a></li><li class="dropdown-item"><!----> <a href="/categories/webpack/" class="nav-link"><i class="undefined"></i>
  webpack
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><a href="/docs/theme-reco/" class="nav-link"><i class="iconfont reco-message"></i>
  随记
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系方式
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/858399075" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/xingyueqianduan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="http://blog.yhxweb.top/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i></i>
  QQ:76120220
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="http://blog.yhxweb.top/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i></i>
  WX:15237156071
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-59e6cb88 data-v-5bb33761><h3 class="title" data-v-59e6cb88>流与二进制</h3> <!----> <label id="box" class="inputBox" data-v-59e6cb88><input type="password" value="" data-v-59e6cb88> <span data-v-59e6cb88>Konck! Knock!</span> <button data-v-59e6cb88>OK</button></label> <div class="footer" data-v-59e6cb88><span data-v-59e6cb88><i class="iconfont reco-theme" data-v-59e6cb88></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59e6cb88>vuePress-theme-reco</a></span> <span data-v-59e6cb88><i class="iconfont reco-copyright" data-v-59e6cb88></i> <a data-v-59e6cb88><span data-v-59e6cb88>星月</span>
          
        <!---->
        2022
      </a></span></div></div> <div data-v-5bb33761><div data-v-5bb33761><main class="page"><section style="display:;"><div class="page-title"><h1 class="title">流与二进制</h1> <div data-v-8a445198><i class="iconfont reco-account" data-v-8a445198><span data-v-8a445198>星月</span></i> <i class="iconfont reco-date" data-v-8a445198><span data-v-8a445198>5/19/2022</span></i> <!----> <i class="tags iconfont reco-tag" data-v-8a445198><span class="tag-item" data-v-8a445198>node.js</span></i></div></div> <div class="theme-reco-content content__default"><h1 id="流与二进制"><a href="#流与二进制" class="header-anchor">#</a> 流与二进制</h1> <h2 id="buffer"><a href="#buffer" class="header-anchor">#</a> Buffer</h2> <p>Buffer只存在于Node环境中，用来表示字节序列，通常当我们使用<code>fs</code>模块读取文件时就可以拿到文件所对应的字节序列（或者说是在内存中的值）。当响应的内容为Buffer时，响应头<code>Content-Type</code>的值为<code>application/octet-stream</code>。</p> <h3 id="buffer-alloc"><a href="#buffer-alloc" class="header-anchor">#</a> <code>Buffer.alloc()</code></h3> <p>可以用来生成指定长度的Buffer，也可以同时指定Buffer字节序列的值。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> buffer <span class="token operator">=</span> Buffer<span class="token punctuation">.</span><span class="token function">alloc</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token comment">// &lt;Buffer 00 00 00 00 00 00 00 00 00 00&gt;</span>
<span class="token keyword">const</span> buffer <span class="token operator">=</span> Buffer<span class="token punctuation">.</span><span class="token function">alloc</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">0xfc</span><span class="token punctuation">)</span> <span class="token comment">// &lt;Buffer fc fc fc fc fc fc fc fc fc fc&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="buffer-from"><a href="#buffer-from" class="header-anchor">#</a> <code>Buffer.from()</code></h3> <p>可以用来获取字符串对应的字节序列（默认UTF8编码）</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> buffer <span class="token operator">=</span> Buffer<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span><span class="token string">'aka'</span><span class="token punctuation">)</span> <span class="token comment">// &lt;Buffer 61 6b 61&gt;  </span>
<span class="token keyword">const</span> buffer <span class="token operator">=</span> Buffer<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span><span class="token string">'你好'</span><span class="token punctuation">)</span> <span class="token comment">// &lt;Buffer e4 bd a0 e5 a5 bd&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="buffer-tostring"><a href="#buffer-tostring" class="header-anchor">#</a> <code>buffer.toString()</code></h3> <p><code>buffer.from()</code>的逆操作，获取字节序列对应的字符串（默认UTF8编码）</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> buffer <span class="token operator">=</span> Buffer<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span><span class="token string">'aka'</span><span class="token punctuation">)</span> 
<span class="token keyword">const</span> str <span class="token operator">=</span> buffer<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// aka</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h2 id="blob"><a href="#blob" class="header-anchor">#</a> Blob</h2> <p><code>Blob</code>只存在于浏览器环境中，可以大致把它视为一个类文件对象（<code>File</code>为<code>Blob</code>的子类）。通常当我们使用<code>fetch</code>发送请求，后端返回<code>Buffer</code>，我们可以使用<code>res.blob()</code>拿到<code>blob</code>：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token function">fetch</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">res</span> <span class="token operator">=&gt;</span> res<span class="token punctuation">.</span><span class="token function">blob</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">blob</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>blob<span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="blob-arraybuffer"><a href="#blob-arraybuffer" class="header-anchor">#</a> <code>blob.arrayBuffer()</code></h3> <p>可以用来将<code>blob</code>转化为<code>arrayBuffer</code>，从而可以看到对应的字节序列。</p> <h3 id="blob-text"><a href="#blob-text" class="header-anchor">#</a> <code>blob.text()</code></h3> <p>可以用来获取<code>blob</code>内部字节序列所对应的文本。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>blob<span class="token punctuation">.</span><span class="token function">text</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">text</span> <span class="token operator">=&gt;</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="url-createobjecturl-blob"><a href="#url-createobjecturl-blob" class="header-anchor">#</a> <code>URL.createObjectURL(blob)</code></h3> <p>当后端将读取的文件作为响应体发送给前端时，我们常见的需求有：①下载文件到本地。②在本地显示图片。</p> <p>这种需求的关键在于根据给定的文件或<code>blob</code>生成一个URL路径，将其放入<code>a</code>或<code>img</code>标签的属性中。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> url <span class="token operator">=</span> <span class="token constant">URL</span><span class="token punctuation">.</span><span class="token function">createObjectURL</span><span class="token punctuation">(</span>blob<span class="token punctuation">)</span>
a<span class="token punctuation">.</span>href <span class="token operator">=</span> url <span class="token comment">// 结构类似于 blob:http://localhost:3000/486ef892-d4fc-485f-b4ab-fae272d35e55</span>
a<span class="token punctuation">.</span>download <span class="token operator">=</span> <span class="token string">'下载文件.txt'</span> <span class="token comment">// 文件名</span>

<span class="token keyword">const</span> url2 <span class="token operator">=</span> <span class="token constant">URL</span><span class="token punctuation">.</span><span class="token function">createObjectURL</span><span class="token punctuation">(</span>blob<span class="token punctuation">)</span>
img<span class="token punctuation">.</span>src <span class="token operator">=</span> url2
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h3 id="blob-slice"><a href="#blob-slice" class="header-anchor">#</a> <code>blob.slice()</code></h3> <p>将文件或<code>blob</code>分割成多个<code>blob</code>，常用于大型图片的上传。</p> <h2 id="file"><a href="#file" class="header-anchor">#</a> File</h2> <p><code>File</code>是<code>Blob</code>的子类，通常我们会在<code>&lt;input type=&quot;file&quot;&gt;</code>中获取到<code>file</code>对象。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> el <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'input'</span><span class="token punctuation">)</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>el<span class="token punctuation">.</span>files<span class="token punctuation">)</span> <span class="token comment">// FileList</span>
el<span class="token punctuation">.</span>files<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token comment">// File</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h2 id="filereader"><a href="#filereader" class="header-anchor">#</a> FileReader</h2> <p><code>blob</code>自带了一些方法来获取二进制、文本、URL。而我们也可以使用<code>FileReader</code>来实现类似的功能。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> reader <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileReader</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
reader<span class="token punctuation">.</span><span class="token function-variable function">onload</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>reader<span class="token punctuation">.</span>result<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
reader<span class="token punctuation">.</span><span class="token function">readAsXXX</span><span class="token punctuation">(</span>blob<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="readasarraybuffer-blob"><a href="#readasarraybuffer-blob" class="header-anchor">#</a> <code>readAsArrayBuffer(blob)</code></h3> <p>类似<code>blob.arrayBuffer()</code></p> <h3 id="readastext-blob"><a href="#readastext-blob" class="header-anchor">#</a> <code>readAsText(blob)</code></h3> <p>类似<code>blob.text()</code></p> <h3 id="readasdataurl-blob"><a href="#readasdataurl-blob" class="header-anchor">#</a> <code>readAsDataURL(blob)</code></h3> <p>用法类似<code>URL.createObjectURL</code>，但实际上两者还是有点不一样。</p> <p>这个方式是将文件内容的字节序列使用Base64编码得到字符串，即以<code>data:application/octet-stream;base64,</code>开头的URL；而<code>URL.createObjectURL()</code>拿到的是一个以<code>blob:http://xxx.com/xxx</code>开头的URL。</p> <h2 id="arraybuffer"><a href="#arraybuffer" class="header-anchor">#</a> ArrayBuffer</h2> <p>简单来说<code>ArrayBuffer</code>是一块内存，但是我们不能直接去操作这块内存，必须通过<code>Typed Array</code>来操作这块内存，<code>Typed Array</code>有<code>Int8Array</code>、<code>Unt8Array</code>、<code>Int16Array</code>等等。</p> <h2 id="stream"><a href="#stream" class="header-anchor">#</a> stream</h2> <p>流对象用来处理Node中的流式数据，<code>Stream</code>继承于<code>eventEmitter</code>，因此实例存在<code>on</code>方法，除此之外流对象的实例存在<code>pipe</code>方法来实现流式数据的传输。</p> <p>流对象有四种类型：</p> <ul><li><code>Writable</code>，比如<code>fs.createWriteStream</code>、<code>process.stdout</code>、<code>res</code></li> <li><code>Readable</code>，比如<code>fs.createReadStream</code>、<code>process.stdin</code>、<code>req</code></li> <li><code>Duplex</code>，可以当成<code>Writable</code>和<code>Readable</code>的结合</li> <li><code>Transform</code></li></ul> <h3 id="writable"><a href="#writable" class="header-anchor">#</a> Writable</h3> <p>对于<code>Writable</code>类型的流对象，实例存在<code>write()</code>和<code>end()</code>方法。</p> <h3 id="readable"><a href="#readable" class="header-anchor">#</a> Readable</h3> <p>对于<code>Readable</code>类型的流对象，实例存在<code>on('data')</code>和<code>on('end')</code>方法。</p> <h3 id="pipeline"><a href="#pipeline" class="header-anchor">#</a> <code>pipeline</code></h3> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> <span class="token punctuation">{</span> stdout<span class="token punctuation">,</span> stdin <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'process'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> <span class="token punctuation">{</span> pipeline <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'stream'</span><span class="token punctuation">)</span>

<span class="token comment">// 写法一</span>
stdin<span class="token punctuation">.</span><span class="token function">on</span><span class="token punctuation">(</span><span class="token string">'data'</span><span class="token punctuation">,</span> <span class="token parameter">chunk</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    stdout<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>chunk<span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment">// 写法二</span>
stdin<span class="token punctuation">.</span><span class="token function">pipe</span><span class="token punctuation">(</span>stdout<span class="token punctuation">)</span>

<span class="token comment">// 写法三</span>
<span class="token function">pipeline</span><span class="token punctuation">(</span>stdin<span class="token punctuation">,</span> stdout<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h2 id="zlib"><a href="#zlib" class="header-anchor">#</a> zlib</h2> <p>Node的<code>Zlib</code>模块提供了基于<code>Stream</code>的API来实现<code>gzip</code>等格式的压缩或解压缩。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> zlib <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'zlib'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> <span class="token punctuation">{</span> pipeline <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'stream'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> gzip <span class="token operator">=</span> zlib<span class="token punctuation">.</span><span class="token function">createGzip</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// 创建一个流对象</span>
<span class="token keyword">const</span> source <span class="token operator">=</span> fs<span class="token punctuation">.</span><span class="token function">createReadStream</span><span class="token punctuation">(</span><span class="token string">'./a.txt'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> target <span class="token operator">=</span> fs<span class="token punctuation">.</span><span class="token function">createWriteStream</span><span class="token punctuation">(</span><span class="token string">'./a.txt.gz'</span><span class="token punctuation">)</span>

<span class="token function">pipeline</span><span class="token punctuation">(</span>source<span class="token punctuation">,</span> gzip<span class="token punctuation">,</span> target<span class="token punctuation">,</span> <span class="token parameter">err</span> <span class="token operator">=&gt;</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment">// 生成压缩文件a.txt.gz</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>当然我们也可以使用基于回调函数的写法来直接对文件进行压缩，经过测试可以把160Kb的页面压缩至4Kb，当浏览器识别到响应头部的<code>Content-Encoding: gzip</code>，浏览器就会<strong>自动对响应的内容进行解压缩</strong>。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// server.js</span>
<span class="token keyword">const</span> <span class="token punctuation">{</span> promisify <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'util'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> fs <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'fs'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> zlib <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'zlib'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> readFile <span class="token operator">=</span> <span class="token function">promisify</span><span class="token punctuation">(</span>fs<span class="token punctuation">.</span>readFile<span class="token punctuation">)</span>
<span class="token keyword">const</span> gzip <span class="token operator">=</span> <span class="token function">promisify</span><span class="token punctuation">(</span>zlib<span class="token punctuation">.</span>gzip<span class="token punctuation">)</span>
<span class="token keyword">const</span> http <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'http'</span><span class="token punctuation">)</span>

http<span class="token punctuation">.</span><span class="token function">createServer</span><span class="token punctuation">(</span><span class="token keyword">async</span> <span class="token punctuation">(</span><span class="token parameter">req<span class="token punctuation">,</span> res</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>req<span class="token punctuation">.</span>url <span class="token operator">===</span> <span class="token string">'/'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">const</span> page <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token function">readFile</span><span class="token punctuation">(</span><span class="token string">'./index.html'</span><span class="token punctuation">)</span>
        <span class="token keyword">const</span> data <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token function">gzip</span><span class="token punctuation">(</span>page<span class="token punctuation">)</span>
        res<span class="token punctuation">.</span><span class="token function">setHeader</span><span class="token punctuation">(</span><span class="token string">'Content-Encoding'</span><span class="token punctuation">,</span> <span class="token string">'gzip'</span><span class="token punctuation">)</span>
        res<span class="token punctuation">.</span><span class="token function">end</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span>
    <span class="token punctuation">}</span> 
    <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>req<span class="token punctuation">.</span>url <span class="token operator">===</span> <span class="token string">'/test'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">let</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">10000</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            obj<span class="token punctuation">[</span>i<span class="token punctuation">]</span> <span class="token operator">=</span> i
        <span class="token punctuation">}</span>
        <span class="token keyword">const</span> data <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token function">gzip</span><span class="token punctuation">(</span><span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span><span class="token punctuation">)</span>
        res<span class="token punctuation">.</span><span class="token function">setHeader</span><span class="token punctuation">(</span><span class="token string">'Content-Encoding'</span><span class="token punctuation">,</span> <span class="token string">'gzip'</span><span class="token punctuation">)</span>
        res<span class="token punctuation">.</span><span class="token function">end</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">listen</span><span class="token punctuation">(</span><span class="token number">3000</span><span class="token punctuation">)</span>

<span class="token comment">// client.js</span>
<span class="token function">fetch</span><span class="token punctuation">(</span><span class="token string">'/test'</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">res</span> <span class="token operator">=&gt;</span> res<span class="token punctuation">.</span><span class="token function">json</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">data</span> <span class="token operator">=&gt;</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment">// 拿到obj</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br></div></div></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">8/8/2022, 7:33:24 PM</span></div></footer> <!----> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-ac050c62><li class="level-2" data-v-ac050c62><a href="/blogs/node/2022/6.html#buffer" class="sidebar-link reco-side-buffer" data-v-ac050c62>Buffer</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#buffer-alloc" class="sidebar-link reco-side-buffer-alloc" data-v-ac050c62>Buffer.alloc()</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#buffer-from" class="sidebar-link reco-side-buffer-from" data-v-ac050c62>Buffer.from()</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#buffer-tostring" class="sidebar-link reco-side-buffer-tostring" data-v-ac050c62>buffer.toString()</a></li><li class="level-2" data-v-ac050c62><a href="/blogs/node/2022/6.html#blob" class="sidebar-link reco-side-blob" data-v-ac050c62>Blob</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#blob-arraybuffer" class="sidebar-link reco-side-blob-arraybuffer" data-v-ac050c62>blob.arrayBuffer()</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#blob-text" class="sidebar-link reco-side-blob-text" data-v-ac050c62>blob.text()</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#url-createobjecturl-blob" class="sidebar-link reco-side-url-createobjecturl-blob" data-v-ac050c62>URL.createObjectURL(blob)</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#blob-slice" class="sidebar-link reco-side-blob-slice" data-v-ac050c62>blob.slice()</a></li><li class="level-2" data-v-ac050c62><a href="/blogs/node/2022/6.html#file" class="sidebar-link reco-side-file" data-v-ac050c62>File</a></li><li class="level-2" data-v-ac050c62><a href="/blogs/node/2022/6.html#filereader" class="sidebar-link reco-side-filereader" data-v-ac050c62>FileReader</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#readasarraybuffer-blob" class="sidebar-link reco-side-readasarraybuffer-blob" data-v-ac050c62>readAsArrayBuffer(blob)</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#readastext-blob" class="sidebar-link reco-side-readastext-blob" data-v-ac050c62>readAsText(blob)</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#readasdataurl-blob" class="sidebar-link reco-side-readasdataurl-blob" data-v-ac050c62>readAsDataURL(blob)</a></li><li class="level-2" data-v-ac050c62><a href="/blogs/node/2022/6.html#arraybuffer" class="sidebar-link reco-side-arraybuffer" data-v-ac050c62>ArrayBuffer</a></li><li class="level-2" data-v-ac050c62><a href="/blogs/node/2022/6.html#stream" class="sidebar-link reco-side-stream" data-v-ac050c62>stream</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#writable" class="sidebar-link reco-side-writable" data-v-ac050c62>Writable</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#readable" class="sidebar-link reco-side-readable" data-v-ac050c62>Readable</a></li><li class="level-3" data-v-ac050c62><a href="/blogs/node/2022/6.html#pipeline" class="sidebar-link reco-side-pipeline" data-v-ac050c62>pipeline</a></li><li class="level-2" data-v-ac050c62><a href="/blogs/node/2022/6.html#zlib" class="sidebar-link reco-side-zlib" data-v-ac050c62>zlib</a></li></ul></main></div> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div><div class="kanbanniang" data-v-5775ee02><div class="banniang-container" style="display:;" data-v-5775ee02><div class="messageBox" style="right:68px;bottom:190px;display:none;" data-v-5775ee02>
      欢迎来到 星月前端博客
    </div> <div class="operation" style="right:90px;bottom:40px;display:;" data-v-5775ee02><i class="kbnfont kbn-ban-home ban-home" data-v-5775ee02></i> <i class="kbnfont kbn-ban-message message" data-v-5775ee02></i> <i class="kbnfont kbn-ban-close close" data-v-5775ee02></i> <a target="_blank" href="https://vuepress-theme-reco.recoluan.com/views/plugins/kanbanniang.html" data-v-5775ee02><i class="kbnfont kbn-ban-info info" data-v-5775ee02></i></a> <i class="kbnfont kbn-ban-theme skin" style="display:none;" data-v-5775ee02></i></div> <canvas id="banniang" width="150" height="220" class="live2d" style="right:90px;bottom:-20px;opacity:0.9;" data-v-5775ee02></canvas></div> <div class="showBanNiang" style="display:none;" data-v-5775ee02>
    看板娘
  </div></div><canvas id="vuepress-canvas-cursor"></canvas></div></div>
    <script src="/assets/js/app.b0d6e6c9.js" defer></script><script src="/assets/js/3.3f705cf6.js" defer></script><script src="/assets/js/1.5432b32a.js" defer></script><script src="/assets/js/51.d9305c51.js" defer></script>
  </body>
</html>
